<?php

declare(strict_types=1);

namespace App\Controller\Admin;

use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Request\Admin\StatisticsRequest;
use App\Service\Admin\StatisticsService;
use Hyperf\Di\Annotation\Inject;

class StatisticsController extends AbstractController
{
    /**
     * @Inject()
     * @var StatisticsService
     */
    protected $statisticsService;

    /**
     * @OperationLog(event="查看运营统计数据",platform="admin")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function index()
    {
        $data = $this->statisticsService->statisticsData();
        return $this->response->success($data);
    }

    /**
     * 获取柱状图数据
     * @param StatisticsRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     * @throws \MongoDB\Driver\Exception\Exception
     */
    public function barChart(StatisticsRequest $request)
    {
      $validated =  $request->validated();
      $validated['date_days'] = $request->input('date_days');
      $validated['start_date'] = $request->input('start_date');
      $validated['end_date'] = $request->input('end_date');
      $data = $this->statisticsService->barChartData($validated);
      return $this->response->success($data);
    }
}
